package cunostinte;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

public class FactsWriter {
	public static void writeFacts(List<Record> oameni) throws IOException{
		String template = new String();
		String tempLine = new String();
		template = "(deftemplate scenariu (slot persoana) (slot actiune) (slot p_locatie) (slot locatie) (slot ora1) (slot min1) (slot sec1) (slot ora2) (slot min2) (slot sec2))";
		BufferedWriter writer = new BufferedWriter(new FileWriter("Jess\\facts.clp"));
			writer.write(template);
		    for(Record rec : oameni){
		      tempLine="(assert(scenariu (persoana \""+rec.getPersoana()+"\") (actiune \""+rec.getActiune()+"\") ";
		      if(rec.hasPLocation()){
		    	  tempLine+="(p_locatie \""+rec.getPLocation()+"\") ";
		      }
		      if(rec.hasLocation()){
		    	  tempLine+="(locatie \""+rec.getLocation()+"\") ";
		      }
		      tempLine+="(ora1 "+rec.getOra1()+") (min1 "+rec.getMin1()+") (sec1 "+rec.getSec1()+") ";
		      tempLine+="(ora2 "+rec.getOra2()+") (min2 "+rec.getMin2()+") (sec2 "+rec.getSec2()+")))";
		      writer.write("\n");
		      writer.write(tempLine);
		    }
		//(assert (scenariu (persoana "Ion") (actiune "se trezeste") 
		//(locatie "dormitor1") (ora1 24) (min1 0) (sec1 30) (ora2 24) (min2 0) (sec2 30)))

		writer.close();
		
	}
}
